﻿using UnityEngine;
using UnityEditor;
using QxFramework.Core;
//[RequireComponent(typeof(Rigidbody2D))]

public class Force : ItemFunc
{
    public float Strength = 100;
    public float Angle = -90;
    private float InteractRadius = 1f;
    public string fireName;
    //  public override string FuncName => "推力";
    //   public override string FuncAbstract => $"给物体施加一个大小为{Strength}N的力";

    Rigidbody2D _rigid;
    CombinableItem item;
    string effectName;
    public override void Awake()
    {
        base.Awake();
        item = GetComponent<CombinableItem>();
    }
    public override void KeyOnInvoke()
    {
        base.KeyOnInvoke();
        item.AddForceAtLocalPosition(Vector3.zero,Strength, Angle);
    }

    public override void KeyDownPreference()
    {
 
        //  throw new System.NotImplementedException();
        effectName = EffectsManager.Instance.Open(fireName, item.transform.position, fireName+"_" + item.ItemFieldSetting.ItemName,
            new System.Tuple<string, float>(item.ItemFieldSetting.ItemName, InteractRadius)).name;
    }

    public override void KeyOnPreference()
    {
     //   throw new System.NotImplementedException();
    }

    public override void KeyUpPreference()
    {
        EffectsManager.Instance.CloseEffect(effectName);
        effectName = default;
    }
    public override void OnDestory()
    {
        base.OnDestory();
        if (effectName != default)
            EffectsManager.Instance.CloseEffect(effectName);
        effectName = default;
    }
}
